<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <?php 
	include "includes/ketnoi.php";
	include "includes/header.php";
	?>
</head>

<body>
    <?php 
	include "includes/narbar.php";

	?>
	<div class="container">
	
		<div class="row">
			<div class="panel-heading">
					<h3 class="panel-title">
					<table class="table table-striped">
					<tr style="background-color:infobackground">
								<th>Công việc</th>
								</tr>
								</h3>
							</table>
						</div>
		 <?php
		

		$user_id = intval($_SESSION['id']);

		 ?>
		 <form method="POST" action="">
		<table class="table table-striped">
	<tr style="background-color:infobackground">
	<td width="20%">Tên việc</td>
    <td><input type="text" name="title" /></td>
	</tr>
	<tr>
	<td>Ngành</td>
	<td><select name ="branch" >

    <?php 
          
       $result=$conn->query("select * from branch");
          while($row=mysqli_fetch_array($result)) 
		  {
echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
    }?>
	</select></td></tr>
	<tr>
	<td>Mô tả</td>
    <td><textarea name="content"/> </textarea></td>
	</tr>
	<tr>
	<td>Mức lương</td>
    <td><input type="text" name="salary" /></td>
	</tr>
	<tr>
	<td>Kinh nghiệm</td>
    <td><input type="text" name="exp" /></td>
	</tr>
	<tr>
	<td>Hạn nộp</td>
    <td><input type="text" name="expire_at" /></td>
	</tr>
	
	<tr>
	<td>Địa điểm</td>
	<td><select name ="id" >

    <?php 
          
       $result=$conn->query("select * from locations");
          while($row=mysqli_fetch_array($result)) 
		  {
echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
    }?>
	</select></td></tr>
	<tr>
	<td></td>
	<td>
    <input type="submit" name="Them" value="Thêm"/></td>
	</tr>
		</table>
	</form><?php
			if(isset($_POST['Them']))
			{		date_default_timezone_set('Asia/Ho_Chi_Minh');
					$now = getdate(); 
					$currentDate = $now["year"] . "-" . $now["mon"] . "-" . $now["mday"]." ".$now["hours"] . ":" . $now["minutes"] . ":" . $now["seconds"];
                    $query ="insert into jobs(branch_id,location_id,user_id,title,content,salary,exp,expire_at,created_at,updated_at) values($_POST[branch],$_POST[id],$user_id,'$_POST[title]','$_POST[content]','$_POST[salary]','$_POST[exp]','$_POST[expire_at]','$currentDate','')";

                    if (!mysql_query($query)) 
                    {
                        die('Error: ' . mysql_error());
                    }
                    echo " Thành công </br>";

                    mysql_close($con);
                
			}	
        ?>
	 
	</div>
	</div>
	<?php
	
	include "includes/footer.php";
	?>
    </body>
</html>
